package omit.wage.controller;


import lombok.extern.slf4j.Slf4j;
import omit.wage.result.PageResult;
import omit.wage.result.Result;
import omit.wage.dto.WageChangeDTO;
import omit.wage.dto.WageModifyDTO;
import omit.wage.dto.WagePageDTO;
import omit.wage.entity.Wage;
import omit.wage.service.IWageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-06-11
 */
@RestController
@RequestMapping
@Slf4j
public class WageController implements Serializable {
    @Autowired
    private IWageService iWageService;

    //分页查询的接口
    @GetMapping("/wage")
    public Result list(@RequestBody WagePageDTO wagePageDTO){
        log.info("分页查询所有工资表的信息,参数为：{}", wagePageDTO);
        PageResult pageResult = iWageService.pageQuery(wagePageDTO);
        return Result.success(pageResult);
    }
    //主键查询的接口
    @GetMapping("/wage/{id}")
    public Result select(@PathVariable Integer id){
        Wage wage = iWageService.getById(id);
        return Result.success(wage);
    }
    //增加工资信息的接口
    @PostMapping("/wage")
    public Result insert(@RequestBody WageModifyDTO wageModifyDTO){
        log.info("新增工资表的信息,参数为：{}", wageModifyDTO);
        iWageService.save(wageModifyDTO);
        return Result.success();
    }
    //修改工资信息的接口
    @PutMapping("/wage")
    public Result update(@RequestBody WageChangeDTO wageChangeDTO){
        log.info("修改工资表的信息,参数为：{}", wageChangeDTO);
        iWageService.update(wageChangeDTO);
        return Result.success();
    }
    //删除工资信息的接口
    @DeleteMapping("/wage/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        iWageService.delete(ids);
        return Result.success();
    }
}
